<!--
 * @Author: 清香白莲 1243327527@qq.com
 * @Date: 2023-08-11 15:04:06
 * @LastEditors: 清香白莲 1243327527@qq.com
 * @LastEditTime: 2023-09-19 16:16:25
 * @FilePath: /shang_study/src/pages/Detail/ImageList/ImageList.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <swiper :options="swiperOption" ref="mySwiper" class="swiper-container">
    <swiper-slide class="swiper_slide_item" v-for="(skuImage, index) in skuImageList" :key="skuImage.id">
      <img :src="skuImage.imgUrl" @click="clickGoodsImage(index)" :class="{active:currentIndex==index}"/>
    </swiper-slide>

    <!-- 如果需要导航按钮 -->
    <div class="swiper-button-prev" slot="button-prev" @click="clickPrev"></div>
    <div class="swiper-button-next" slot="button-next" @click="clickNext"></div>
  </swiper>
</template>

<script>

import Swiper from 'swiper'
export default {
  name: "ImageList",
  data() {
    return {
      swiperOption: {
        //幻灯片放映方向
        direction: 'horizontal', //通常不与左右按钮一同使用
        //前进后退按钮
        navigation: {
          nextEl: '.swiper-button-next',
          prevEl: '.swiper-button-prev'
        },
        slidesPerView: 6,
        slidesPerGroup: 1,
        //幻灯片播放配置项
        loop: false, //是否循环播放
        speed: 1000, // 发生页面切换动画时，动画的切换速度
        on: {
          slideChangeTransitionEnd: function () {
            //每次切换结束时，在控制台打印现在是第几个slide
            console.log('end',this.swiper);
          },
        },
      },
      currentIndex: 0,
    }
  },
  props: ['skuImageList'],
  methods: {
    clickGoodsImage(index) {
      this.currentIndex = index;
      this.$bus.$emit('clickGoodsImage', index);
    },
    clickPrev() {
      // if (this.currentIndex > 0) {
      //   this.currentIndex = this.currentIndex - 1;
      // }
    },
    clickNext() {
      // if (this.currentIndex < (this.skuImageList.length - 1)) {
      //   this.currentIndex = this.currentIndex + 1;
      // }
    }
  },
  computed: {
    swiper() {
      return this.$refs.mySwiper.$swiper;
    },
  }
}
</script>

<style lang="less" scoped>
.swiper-container {
  height: 56px;
  width: 412px;
  box-sizing: border-box;
  padding: 0 12px;

  .swiper-slide {
    width: 56px;
    height: 56px;

    img {
      width: 100%;
      height: 100%;
      border: 1px solid #ccc;
      padding: 2px;
      width: 50px;
      height: 50px;
      display: block;

      &.active {
        border: 2px solid #f60;
        padding: 1px;
      }

      // &:hover {
      //   border: 2px solid #f60;
      //   padding: 1px;
      // }
    }
  }

  .swiper-button-next {
    left: auto;
    right: 0;
  }

  .swiper-button-prev {
    left: 0;
    right: auto;
  }

  .swiper-button-next,
  .swiper-button-prev {
    box-sizing: border-box;
    width: 12px;
    height: 56px;
    background: rgb(235, 235, 235);
    border: 1px solid rgb(204, 204, 204);
    top: 0;
    margin-top: 0;

    &::after {
      font-size: 12px;
    }
  }
}
</style>